#coding=utf-8
#import libs 
import sys
import os
from   os.path import abspath, dirname
sys.path.insert(0,abspath(dirname(__file__)))
import simulation_cmd
import simulation_sty
import Fun
import EXUIControl
EXUIControl.FunLib = Fun
EXUIControl.G_ExeDir = Fun.G_ExeDir
EXUIControl.G_ResDir = Fun.G_ResDir
import tkinter
from   tkinter import *
import tkinter.ttk
import tkinter.font
from   PIL import Image,ImageTk

#Add your Varial Here: (Keep This Line of comments)
#Define UI Class
class  simulation:
    def __init__(self,root,isTKroot = True,params=None):
        uiName = Fun.GetUIName(root,self.__class__.__name__)
        self.uiName = uiName
        Fun.Register(uiName,'UIClass',self)
        self.root = root
        self.isTKroot = isTKroot
        self.firstRun = True
        Fun.G_UIParamsDictionary[uiName]=params
        Fun.G_UICommandDictionary[uiName]=simulation_cmd
        Fun.Register(uiName,'root',root)
        style = simulation_sty.SetupStyle(isTKroot)
        if isTKroot == True:
            Fun.SetTitleBar(root,titleText='Form1',isDarkMode=False)
            Fun.CenterDlg(uiName,root,527,649)
            Fun.WindowDraggable(root,False,0,'#ffffff')
            root.wm_attributes("-topmost",1)
            root['background'] = '#EFEFEF'
        Form_1= tkinter.Canvas(root,width = 10,height = 4)
        Form_1.pack(side=tkinter.TOP,fill=tkinter.BOTH,expand=True)
        Form_1.configure(width = 527)
        Form_1.configure(height = 649)
        Form_1.configure(bg = "#EFEFEF")
        Form_1.configure(highlightthickness = 0)
        Fun.Register(uiName,'Form_1',Form_1)
        Fun.SetUIRootSize(uiName,527,649)
        #Create the elements of root 
        Frame_3 = tkinter.Frame(Form_1)
        Fun.Register(uiName,'PyMe_Frame_3',Frame_3,'Frame_1')
        Fun.SetControlPlace(uiName,'PyMe_Frame_3',0,-3,978,923,'nw',True,True)#lock
        Frame_3.configure(bg = "#CCCCCC")
        Button_5 = tkinter.Button(Frame_3,text="Del")
        Fun.Register(uiName,'PyMe_Button_5',Button_5,'Button_1')
        Fun.SetControlPlace(uiName,'PyMe_Button_5',379,17,120,48,'nw',True,True)
        Button_5.configure(bg = "#EFEFEF")
        Button_5.configure(fg = "#000000")
        Button_28 = tkinter.Button(Frame_3,text="开始运行")
        Fun.Register(uiName,'PyMe_Button_28',Button_28,'Button_2')
        Fun.SetControlPlace(uiName,'PyMe_Button_28',379,448,120,48,'nw',True,True)
        Button_28.configure(bg = "#EFEFEF")
        Button_28.configure(fg = "#000000")
        Button_28.configure(activebackground = "#656D78")
        Button_28.configure(command=lambda:Fun.CommandFunction_Adaptor(simulation_cmd.Button_2_onCommand,uiName,"Button_2"))
        Button_29 = tkinter.Button(Frame_3,text="停止")
        Fun.Register(uiName,'PyMe_Button_29',Button_29,'Button_3')
        Fun.SetControlPlace(uiName,'PyMe_Button_29',379,536,120,48,'nw',True,True)
        Button_29.configure(bg = "#EFEFEF")
        Button_29.configure(fg = "#000000")
        Button_29.configure(command=lambda:Fun.CommandFunction_Adaptor(simulation_cmd.Button_3_onCommand,uiName,"Button_3"))
        Button_30 = tkinter.Button(Frame_3,text="选择")
        Fun.Register(uiName,'PyMe_Button_30',Button_30,'Button_4')
        Fun.SetControlPlace(uiName,'PyMe_Button_30',43,422,80,30,'nw',True,True)
        Button_30.configure(bg = "#EFEFEF")
        Button_30.configure(fg = "#000000")
        Button_30.configure(command=lambda:Fun.CommandFunction_Adaptor(simulation_cmd.Button_4_onCommand,uiName,"Button_4"))
        Button_30_Ft=tkinter.font.Font(family='Microsoft YaHei UI', size=8,weight='normal',slant='roman',underline=0,overstrike=0)
        Button_30.configure(font = Button_30_Ft)
        Label_6 = tkinter.Label(Frame_3,text="device_id")
        Fun.Register(uiName,'PyMe_Label_6',Label_6,'Label_1')
        Fun.SetControlPlace(uiName,'PyMe_Label_6',43,45,80,30,'nw',True,True)
        Label_6.configure(bg = "#EFEFEF")
        Label_6.configure(fg = "SystemButtonText")
        Label_6_Ft=tkinter.font.Font(family='System', size=8,weight='bold',slant='roman',underline=0,overstrike=0)
        Label_6.configure(font = Label_6_Ft)
        Label_8 = tkinter.Label(Frame_3,text="电量")
        Fun.Register(uiName,'PyMe_Label_8',Label_8,'Label_2')
        Fun.SetControlPlace(uiName,'PyMe_Label_8',43,89,80,30,'nw',True,True)
        Label_8.configure(bg = "#EFEFEF")
        Label_8.configure(fg = "SystemButtonText")
        Label_8_Ft=tkinter.font.Font(family='System', size=8,weight='bold',slant='roman',underline=0,overstrike=0)
        Label_8.configure(font = Label_8_Ft)
        Label_10 = tkinter.Label(Frame_3,text="accel")
        Fun.Register(uiName,'PyMe_Label_10',Label_10,'Label_3')
        Fun.SetControlPlace(uiName,'PyMe_Label_10',43,131,80,30,'nw',True,True)
        Label_10.configure(bg = "#EFEFEF")
        Label_10.configure(fg = "SystemButtonText")
        Label_10_Ft=tkinter.font.Font(family='System', size=8,weight='bold',slant='roman',underline=0,overstrike=0)
        Label_10.configure(font = Label_10_Ft)
        Label_12 = tkinter.Label(Frame_3,text="steer")
        Fun.Register(uiName,'PyMe_Label_12',Label_12,'Label_4')
        Fun.SetControlPlace(uiName,'PyMe_Label_12',43,178,80,30,'nw',True,True)
        Label_12.configure(bg = "#EFEFEF")
        Label_12.configure(fg = "SystemButtonText")
        Label_12_Ft=tkinter.font.Font(family='System', size=8,weight='bold',slant='roman',underline=0,overstrike=0)
        Label_12.configure(font = Label_12_Ft)
        Label_14 = tkinter.Label(Frame_3,text="device_type")
        Fun.Register(uiName,'PyMe_Label_14',Label_14,'Label_5')
        Fun.SetControlPlace(uiName,'PyMe_Label_14',43,221,80,30,'nw',True,True)
        Label_14.configure(bg = "#EFEFEF")
        Label_14.configure(fg = "SystemButtonText")
        Label_14_Ft=tkinter.font.Font(family='System', size=8,weight='bold',slant='roman',underline=0,overstrike=0)
        Label_14.configure(font = Label_14_Ft)
        Label_16 = tkinter.Label(Frame_3,text="odom")
        Fun.Register(uiName,'PyMe_Label_16',Label_16,'Label_6')
        Fun.SetControlPlace(uiName,'PyMe_Label_16',43,269,80,30,'nw',True,True)
        Label_16.configure(bg = "#EFEFEF")
        Label_16.configure(fg = "SystemButtonText")
        Label_16_Ft=tkinter.font.Font(family='System', size=8,weight='bold',slant='roman',underline=0,overstrike=0)
        Label_16.configure(font = Label_16_Ft)
        Label_20 = tkinter.Label(Frame_3,text="速度")
        Fun.Register(uiName,'PyMe_Label_20',Label_20,'Label_7')
        Fun.SetControlPlace(uiName,'PyMe_Label_20',43,315,80,30,'nw',True,True)
        Label_20.configure(bg = "#EFEFEF")
        Label_20.configure(fg = "SystemButtonText")
        Label_20_Ft=tkinter.font.Font(family='Microsoft YaHei UI', size=8,weight='normal',slant='roman',underline=0,overstrike=0)
        Label_20.configure(font = Label_20_Ft)
        Label_22 = tkinter.Label(Frame_3,text="路径")
        Fun.Register(uiName,'PyMe_Label_22',Label_22,'Label_8')
        Fun.SetControlPlace(uiName,'PyMe_Label_22',43,359,80,30,'nw',True,True)
        Label_22.configure(bg = "#EFEFEF")
        Label_22.configure(fg = "SystemButtonText")
        Label_22_Ft=tkinter.font.Font(family='Microsoft YaHei UI', size=8,weight='normal',slant='roman',underline=0,overstrike=0)
        Label_22.configure(font = Label_22_Ft)
        Label_24 = tkinter.Label(Frame_3,text="周期")
        Fun.Register(uiName,'PyMe_Label_24',Label_24,'Label_9')
        Fun.SetControlPlace(uiName,'PyMe_Label_24',43,600,80,30,'nw',True,True)
        Label_24.configure(bg = "#EFEFEF")
        Label_24.configure(fg = "SystemButtonText")
        Label_26 = tkinter.Label(Frame_3,text="km/h")
        Fun.Register(uiName,'PyMe_Label_26',Label_26,'Label_10')
        Fun.SetControlPlace(uiName,'PyMe_Label_26',299,315,80,30,'nw',True,True)
        Label_26.configure(bg = "#EFEFEF")
        Label_26.configure(fg = "SystemButtonText")
        Label_26_Ft=tkinter.font.Font(family='System', size=8,weight='bold',slant='roman',underline=0,overstrike=0)
        Label_26.configure(font = Label_26_Ft)
        Label_27 = tkinter.Label(Frame_3,text="hz")
        Fun.Register(uiName,'PyMe_Label_27',Label_27,'Label_11')
        Fun.SetControlPlace(uiName,'PyMe_Label_27',299,600,80,30,'nw',True,True)
        Label_27.configure(bg = "#EFEFEF")
        Label_27.configure(fg = "SystemButtonText")
        Entry_7= EXUIControl.CustomEntry(Frame_3)
        Fun.Register(uiName,'PyMe_Entry_7',Entry_7,'Entry_1')
        Entry_7.SetBGColor("#FFFFFF")
        Entry_7.SetBGColor_ReadOnly("#EFEFEF")
        Entry_7.SetFGColor("#000000")
        Entry_7_Font=tkinter.font.Font(family='Microsoft YaHei UI', size=8,weight='normal',slant='roman',underline=0,overstrike=0)
        Entry_7.SetFont(Entry_7_Font)
        Entry_7.SetTipFGColor("#888888")
        Entry_7.SetRelief("sunken")
        Fun.SetControlPlace(uiName,'PyMe_Entry_7',153,45,120,30,'nw',True,True)
        Entry_9= EXUIControl.CustomEntry(Frame_3)
        Fun.Register(uiName,'PyMe_Entry_9',Entry_9,'Entry_2')
        Entry_9.SetBGColor("#FFFFFF")
        Entry_9.SetBGColor_ReadOnly("#EFEFEF")
        Entry_9.SetFGColor("#000000")
        Entry_9.SetTipFGColor("#888888")
        Entry_9.SetRelief("sunken")
        Fun.SetControlPlace(uiName,'PyMe_Entry_9',153,89,120,30,'nw',True,True)
        Entry_11= EXUIControl.CustomEntry(Frame_3)
        Fun.Register(uiName,'PyMe_Entry_11',Entry_11,'Entry_3')
        Entry_11.SetBGColor("#FFFFFF")
        Entry_11.SetBGColor_ReadOnly("#EFEFEF")
        Entry_11.SetFGColor("#000000")
        Entry_11.SetTipFGColor("#888888")
        Entry_11.SetRelief("sunken")
        Fun.SetControlPlace(uiName,'PyMe_Entry_11',153,131,120,30,'nw',True,True)
        Entry_13= EXUIControl.CustomEntry(Frame_3)
        Fun.Register(uiName,'PyMe_Entry_13',Entry_13,'Entry_4')
        Entry_13.SetBGColor("#FFFFFF")
        Entry_13.SetBGColor_ReadOnly("#EFEFEF")
        Entry_13.SetFGColor("#000000")
        Entry_13.SetTipFGColor("#888888")
        Entry_13.SetRelief("sunken")
        Fun.SetControlPlace(uiName,'PyMe_Entry_13',153,178,120,30,'nw',True,True)
        Entry_15= EXUIControl.CustomEntry(Frame_3)
        Fun.Register(uiName,'PyMe_Entry_15',Entry_15,'Entry_5')
        Entry_15.SetBGColor("#FFFFFF")
        Entry_15.SetBGColor_ReadOnly("#EFEFEF")
        Entry_15.SetFGColor("#000000")
        Entry_15.SetTipFGColor("#888888")
        Entry_15.SetRelief("sunken")
        Fun.SetControlPlace(uiName,'PyMe_Entry_15',153,224,120,30,'nw',True,True)
        Entry_17= EXUIControl.CustomEntry(Frame_3)
        Fun.Register(uiName,'PyMe_Entry_17',Entry_17,'Entry_6')
        Entry_17.SetBGColor("#FFFFFF")
        Entry_17.SetBGColor_ReadOnly("#EFEFEF")
        Entry_17.SetFGColor("#000000")
        Entry_17.SetTipFGColor("#888888")
        Entry_17.SetRelief("sunken")
        Fun.SetControlPlace(uiName,'PyMe_Entry_17',153,269,120,30,'nw',True,True)
        Entry_21= EXUIControl.CustomEntry(Frame_3)
        Fun.Register(uiName,'PyMe_Entry_21',Entry_21,'Entry_7')
        Entry_21.SetBGColor("#FFFFFF")
        Entry_21.SetBGColor_ReadOnly("#EFEFEF")
        Entry_21.SetFGColor("#000000")
        Entry_21.SetTipFGColor("#888888")
        Entry_21.SetRelief("sunken")
        Fun.SetControlPlace(uiName,'PyMe_Entry_21',153,315,120,30,'nw',True,True)
        Entry_25= EXUIControl.CustomEntry(Frame_3)
        Fun.Register(uiName,'PyMe_Entry_25',Entry_25,'Entry_8')
        Entry_25.SetBGColor("#FFFFFF")
        Entry_25.SetBGColor_ReadOnly("#EFEFEF")
        Entry_25.SetFGColor("#000000")
        Entry_25.SetTipFGColor("#888888")
        Entry_25.SetRelief("sunken")
        Fun.SetControlPlace(uiName,'PyMe_Entry_25',153,600,120,30,'nw',True,True)
        Text_23= EXUIControl.CustomText(Frame_3,True)
        Fun.Register(uiName,'PyMe_Text_23',Text_23,'Text_1')
        Text_23.SetRelief("sunken")
        Fun.SetControlPlace(uiName,'PyMe_Text_23',153,366,194,213,'nw',True,True)
        #Inital all element's Data 
        Fun.InitElementData(uiName)
        #Call Form_1's OnLoad Function
        Fun.RunForm1_CallBack(uiName,"Load",simulation_cmd.Form_1_onLoad)
        #Add Some Logic Code Here: (Keep This Line of comments)



        #Exit Application: (Keep This Line of comments)
        if self.isTKroot == True and Fun.GetElement(self.uiName,"root"):
            self.root.protocol('WM_DELETE_WINDOW', self.Exit)
            self.root.bind('<Configure>', self.Configure)
            
    def GetRootSize(self):
        return Fun.GetUIRootSize(self.uiName)
    def GetAllElement(self):
        return Fun.G_UIElementDictionary[self.uiName]
    def Escape(self,event):
        if Fun.AskBox('提示','确定退出程序？') == True:
            self.Exit()
    def Exit(self):
        if self.isTKroot == True:
            Fun.DestroyUI(self.uiName)

    def Configure(self,event):
        Form_1 = Fun.GetElement(self.uiName,'Form_1')
        if Form_1 == event.widget:
            Fun.ReDrawCanvasRecord(self.uiName)
        if self.root == event.widget:
            Fun.ResizeRoot(self.uiName,self.root,event)
            Fun.ResizeAllChart(self.uiName)
            uiName = self.uiName
            pass
        Fun.ActiveElement(self.uiName,event.widget)
#Create the root of Kinter 
if  __name__ == '__main__':
    Fun.RunApplication(simulation)
